﻿using NHibernate;
using NHibernate.Criterion;
using System.Collections.Generic;
using MSP.Data.Domain;
using MSP.Data.NHibernate;

namespace MSP.Data.Repositories
{
    public class CustomerRepository : Repository<Customer>
    {
        public CustomerRepository(ISession session)
            : base(session)
        {
        }

        public void SaveCustomer(Customer customer)
        {
            Add(customer);
        }

        public void UpdateCustomer(Customer customer)
        {
            Update(customer);
        }

        public void DeleteCustomer(int Id)
        {
            Customer customer = GetCustomerById(Id);
            if (customer != null)
                Delete(customer);
        }

        public Customer GetCustomerById(int Id)
        {
            return Session.CreateCriteria<Customer>()
                          .Add(Restrictions.Eq("Id", Id))
                          .UniqueResult<Customer>();
        }

        public IList<Customer> GetAllCustomer()
        {
            return (Session.CreateCriteria<Customer>()
               .List<Customer>() as List<Customer>);
        }

    }
}
